﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminSite.Master" AutoEventWireup="true"
    CodeBehind="ProductList.aspx.cs" Inherits="phudieuhungthinh.Admin.ProductList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
     .btn-add
    {
        background-color: #ccc;
        color: black;
        font-family: 'Oswald';
        font-size: 20px;
        text-decoration: none;
        cursor: poiner;
        border:none;
    }
</style>
<script type="text/javascript">
    function addProductClick() {
        window.location.href = '/Admin/ProductItem.aspx';
    }
    function ClickDelete(id) {
        var answer = confirm("Bạn có muốn xóa sản phẩm này");
        if (answer) {                
            $.ajax({
                type: "POST",
                url: "/Admin/ProductList.aspx/DeleteProduct",
                data: JSON.stringify({ productId: id }),
                contentType: "application/json",
                success: function (data) {
                    window.location.href = "/Admin/ProductList.aspx";
                },
                error: function () {
                    alert("Fail");
                }
            });
        }
    }
    $(document).ready(function () {
        //Prepare jtable plugin
        $('#ProductTableContainer').jtable({
            title: 'Danh sách sản phẩm',
            paging: true, //Enable paging
            pageSize: 5, //Set page size (default: 10)
            sorting: true, //Enable sorting
            defaultSorting: 'Name ASC', //Set default sorting
            actions: {
                listAction: '/Admin/ProductList.aspx/GetProductList',
            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                Name: {
                    title: 'Sản phẩm',
                    width: '50%'
                },
                Price: {
                    title: 'Giá',
                    width: '25%'
                },
                CustomImage: {
                    title: 'Hình ảnh',
                    width: '100px',
                    sorting: false,
                    create: false,
                    edit: false,
                    list: true,
                    display: function (data) {
                        return '<img width="100" src="/Images/Products/thumb/' + data.record.ImageUrl + '"/>';
                    }
                },
                CustomEditAction: {
                    title: 'Sửa',
                    width: '50px',
                    sorting: false,
                    create: false,
                    edit: false,
                    list: true,
                    display: function (data) {
                        return '<a href="ProductItem.aspx?id=' + data.record.ID + '">Edit</a>';
                    }
                },
                CustomDeleteAction: {
                    title: 'Xóa',
                    width: '50px',
                    sorting: false,
                    create: false,
                    edit: false,
                    list: true,
                    display: function (data) {
                        if (data.record) {
                            return "<a onclick=\"javascript:ClickDelete('" + data.record.ID + "'); return false;\">Delete</a>";
                        }
                        return null;
                    }
                }
            }
        });
        //Load category list from server
        $('#ProductTableContainer').jtable('load');
    }); 
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div>
        <input type="button" class="btn-add" value="Thêm sản phẩm" onclick="javascript:addProductClick()" />
    </div>
    <div id="ProductTableContainer">
    </div>
</asp:Content>
